
set(BUNDLE_ICON       "assets/icon.png")
set(BUNDLE_PREFIX     "dist/${PROJECT_NAME}")
set(BUNDLE_PACKAGE    "com.gitee.zinface.${PROJECT_NAME}")
set(BUNDLE_EXECUTABLE "${BUNDLE_PACKAGE}/${PROJECT_NAME}")

if(EXISTS ${CMAKE_SOURCE_DIR}/${BUNDLE_PREFIX}/_internal)
    install(DIRECTORY ${BUNDLE_PREFIX}/_internal
        DESTINATION /opt/apps/${BUNDLE_PACKAGE}
    )
    install(PROGRAMS ${BUNDLE_PREFIX}/${PROJECT_NAME}
        DESTINATION /opt/apps/${BUNDLE_PACKAGE}
    )
    install(FILES
        ${BUNDLE_ICON}
        DESTINATION /usr/share/icons/hicolor/512x512/apps
        RENAME ${BUNDLE_PACKAGE}.png
    )
else()
    install(DIRECTORY ${BUNDLE_PREFIX}
        DESTINATION /opt/apps/${BUNDLE_PACKAGE}
    )
    install(PROGRAMS ${BUNDLE_PREFIX}/${PROJECT_NAME}
        DESTINATION /opt/apps/${BUNDLE_PACKAGE}
    )
    set(BUNDLE_EXECUTABLE ${BUNDLE_EXECUTABLE}/${PROJECT_NAME})
    install(FILES
        ${BUNDLE_ICON}
        DESTINATION /usr/share/icons/hicolor/512x512/apps
        RENAME ${BUNDLE_PACKAGE}.png
    )
endif(EXISTS ${CMAKE_SOURCE_DIR}/${BUNDLE_PREFIX}/_internal)

##
# [Desktop Entry] For Linux 
# 内容默认应用名称: Name= 应与项目名称相同
spark_desktop_macros(
    # 应用名称: Name=
    "Ollama Qwen Client"
    # 应用名称: Name[zh_CN]=
    "Ollama 千问客户端"
    # 应用说明: Comment=
    "基于 PySide6 的 Ollama 千问客户端"
    # 应用类型: Type=
    "Application"
    # 执行程序: Exec=
    "/opt/apps/${BUNDLE_EXECUTABLE}"
    # 图标路径: Icon=
    "${BUNDLE_PACKAGE}"
    # 应用分类: Categories=
    "Utility"
    # MIME类型: MimeType=
)
install(FILES ${SPARK_DESKTOP_FILE}
    DESTINATION /usr/share/applications
    RENAME ${BUNDLE_PACKAGE}.desktop
)
##
# [deb] For Linux(with dpkg)
# 注释行(使用方式)
add_package_descript(cmake/spark-deb-package.descript)

# spark_include(cmake/SparkAppimageConfig.cmake)  # 导入来自 Spark 构建的 Appimage 构建
add_appimage_icon(${BUNDLE_ICON})       # 添加到 Appimage 中的默认的图标
add_appimage_desktop()                    # 添加到 Appimage 中的默认desktop(使用来自 Spark 构建的 Desktop 构建中配置的信息(必须要求 spark-desktop))
add_appimage_dir(${PROJECT_NAME} dist/${PROJECT_NAME})      # 添加到 Appimage 中的默认目标，应用对 Appimage 的构建
